package org.xzx.shop_api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.data.domain.Page;
import org.xzx.shop_api.entity.Goods;
import org.xzx.shop_api.mapper.GoodsMapper;
import org.xzx.shop_api.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public int addGoods(Goods goods) {
        return goodsMapper.insert(goods);
    }

    @Override
    public List<Goods> getGoodsByCateId(int cateId, int level) {
        QueryWrapper<Goods> queryWrapper = new QueryWrapper<>();
        if (level == 1) {
            queryWrapper.eq("first_cate_id", cateId);
        }
        if (level == 2) {
            queryWrapper.eq("second_cate_id", cateId);
        }
        if (level == 3) {
            queryWrapper.eq("third_cate_id", cateId);
        }
        //上架状态
        queryWrapper.eq("status", 1);
        queryWrapper.orderByDesc("sales_number");
        return goodsMapper.selectList(queryWrapper);
    }

    @Override
    public Goods getGoodsById(int id) {
        QueryWrapper<Goods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", id);
        //上架状态
        queryWrapper.eq("status", 1);
        return goodsMapper.selectOne(queryWrapper);
    }



}
